package club.yuit.desktop.ui;

import javax.swing.*;
import java.awt.*;

/**
 * @author: yuit
 * @date: 2023/12/12 16:10
 */
public class KeyValuePropertyPanel  extends JPanel {
    private JTextField keyField;
    private JTextField valueField;
    private JButton remove;

    JPanel parent;
    public KeyValuePropertyPanel(JPanel parent) {
        this.setLayout(new FlowLayout(FlowLayout.LEFT));
        keyField = new JTextField();
        keyField.putClientProperty("JTextField.placeholderText","Key");
        valueField = new JTextField();
        valueField.putClientProperty("JTextField.placeholderText","Value");
        remove = new JButton();
        remove.putClientProperty("JButton.buttonType", "roundRect");
        remove.setText("-");
        this.parent = parent;
        this.add(keyField);
        this.add(valueField);
        this.add(remove);
        remove.addActionListener(e->{
            parent.remove(this);
            parent.updateUI();
        });

        remove.setToolTipText("删除");
    }


    public String getKey(){
        return keyField.getText();
    }

    public String getValue(){
        return valueField.getText();
    }
}
